package cn.lsh.hive;

import java.sql.*;
import java.util.Map;

public class JdbcUtil {

	public static void main(String[] args) {
		Connection conn = null;
		try {
			Class.forName("org.apache.hive.jdbc.HiveDriver");
			conn = DriverManager.getConnection("jdbc:hive2://node00:10000/test", "root", "");
			Statement statement = conn.createStatement();
			ResultSet rst = statement.executeQuery("select * from user4");
			System.out.println("id	 name	 age		sex		lieks			address");
			while (rst.next()) {
				int id = rst.getInt("id");
				String name = rst.getString("name");
				int age = rst.getInt("age");
				String sex = rst.getInt("sex") == 0 ? "女" : "男";
				String likes = rst.getString("likes");
				String address = rst.getString("address");
				System.out.println(id + "     " + name + "     " + age + "   " + sex + "     " + likes + "     " + address);
			}
		} catch (Exception throwables) {
			throwables.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException throwables) {
				throwables.printStackTrace();
			}
		}
	}
}
